package com.mrd.projects.weixinapi.dbutil;

/**
 * Created by luob on 2015/12/28 0028.
 */

import com.mrd.projects.weixinapi.util.WeixinApiConfigUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectDb {
    private static String driveClassName = WeixinApiConfigUtil.getValue("db.driveClassName");
    private static String url = WeixinApiConfigUtil.getValue("db.url");

    private static String user = WeixinApiConfigUtil.getValue("db.user");
    private static String password = WeixinApiConfigUtil.getValue("db.password");

    static {

    }

    public static Connection Connect() {
        Connection conn = null;

        //load driver
        try {
            Class.forName(driveClassName);
        } catch (ClassNotFoundException e) {
            System.out.println("load driver failed!");
            e.printStackTrace();
        }

        //connect db
        try {
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            System.out.println("connect failed!");
            e.printStackTrace();
        }

        return conn;
    }
}

